<template>
	<view class=" pb-3">
		<public-module></public-module>
		<u-sticky>
			<view class="bg-white p-2 mb-2">
				<u-tabs :list="tabsList" @click="clickTab" :scrollable="false"></u-tabs>
			</view>
		</u-sticky>
		<view class="px-2">
			<view class="flex j-start p-2 bg-white rounded-10 mb-2" v-for="(item,index) in listData" :key="item.id">
				<u--image :showLoading="true" :src="item.img" width="170rpx" height="170rpx" :radius="10">
					<view slot="error" style="font-size: 22rpx;">图片加载失败</view>
				</u--image>
				<view class="flex-1 ml-2">
					<view class="mb-1 font-bold ellipsis">三等奖</view>
					<view class="mb-1 font-30 ellipsis2">雨伞</view>
					<view class="text-secondary mb-1">中奖时间：2024-09-20 12:20:20</view>
					<view class="text-secondary mb-1">兑奖开始时间：2024-09-20 12:20:20</view>
					<view class="text-secondary mb-1">兑奖结束时间：2024-09-20 12:20:20</view>
					<view class="flex j-end mt-2">
						<view class="flex j-center a-center h-60 rounded-20 text-white bg-warning col-5">
							兑奖
						</view>
					</view>
				</view>
			</view>
		</view>
		<empty v-if="listData.length==0" />
	</view>
</template>

<script>
	import {
		activityList
	} from '@/api/active.js'

	export default {
		data() {
			return {
				tabsList: [{
						name: '未领奖'
					},
					{
						name: '已领奖'
					},
					{
						name: '已失效'
					}
				],
				queryParams: {
					pageNo: 1,
					pageSize: 15,
				},
				listData: []
			}
		},
		onLoad() {
			this.getDataLists()
		},
		onPullDownRefresh() {
			this.isLoadMore = false;
			this.queryParams.pageNo = 1;
			this.listData = [];
			this.getDataLists();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		onReachBottom() {
			if (!this.isLoadMore) {
				this.isLoadMore = true;
				this.queryParams.pageNo += 1;
				this.getDataLists();
			}
		},
		methods: {
			clickTab() {
				this.isLoadMore = false;
				this.queryParams.pageNo = 1;
				this.listData = [];
				this.getDataLists();
			},
			getDataLists() {
				activityList(this.queryParams).then(res => {
					if (res.data.list.length == 0) {
						let oldLoad = {}
						this.isLoadMore = true;
						oldLoad = Object.assign({}, this.queryParams);
						oldLoad.pageNo = this.queryParams.pageNo;
						this.queryParams = oldLoad
						this.$forceUpdate()
						return
					}

					this.isLoadMore = false;
					let oldList = this.listData || []
					oldList.push(...res.data.list)
					this.listData = oldList
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>